//
//  OrderDetailInfoCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/6.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "OrderDetailInfoCell.h"

@interface OrderDetailInfoCell()

@property (nonatomic,strong) UILabel *titleLB;
@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UILabel *orderNoLB;
@property (nonatomic,strong) UILabel *orderTimeLB;
@property (nonatomic,strong) UILabel *orderPayTimeLB;
@property (nonatomic,strong) UILabel *orderDeliverTimeLB;
@property (nonatomic,strong) UILabel *orderTrackLB;

@property (nonatomic,strong) UIButton *pasteBtn;

@end

@implementation OrderDetailInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = MainBackColor;
        self.contentView.backgroundColor = MainBackColor;
        
        [self initUI];
    }
    return self;
}
#pragma mark - setter
- (void)setModel:(OrderDetailModel *)model{
    _model = model;
    self.orderNoLB.text = _model.orderno;
    self.orderTimeLB.text = _model.time;
    self.orderPayTimeLB.text = _model.paydate;
    self.orderDeliverTimeLB.text = _model.outdate;
    self.orderTrackLB.text = _model.express;
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.titleLB];
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.pasteBtn];
    
    NSArray *titles = @[@"订单编号：",@"下单时间：",@"付款时间：",@"发货时间：",@"物流公司："];
    for (int i = 0; i<5; i++) {
        UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(15, 20+i*30, 80, 20)];
        lb.font = FontSet(14);
        lb.textColor = MainGrayTextColor;
        lb.text = titles[i];
        lb.textAlignment = NSTextAlignmentLeft;
        [self.bgView addSubview:lb];
        
        UILabel *lb1 = [[UILabel alloc] initWithFrame:CGRectMake(lb.right+10, lb.top, ScreenWidth-160, 20)];
        lb1.font = FontSet(14);
        lb1.textColor = MainGrayTextColor;
        lb1.textAlignment = NSTextAlignmentLeft;
        [self.bgView addSubview:lb1];
        
        if (i == 0) {
            self.orderNoLB = lb1;
        }else if (i==1) {
            self.orderTimeLB = lb1;
        }else if (i==2) {
            self.orderPayTimeLB = lb1;
        }else if (i==3) {
            self.orderDeliverTimeLB = lb1;
        }else if (i==4) {
            self.orderTrackLB = lb1;
        }
    }
    float height = self.bgView.bottom;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.updateCellHeightBlock) {
            self.updateCellHeightBlock(height);
        }
    });
}
#pragma mark - lazy
- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(17, 23, 120, 20)];
        _titleLB.textColor = MainBlackTextColor;
        _titleLB.font = FontSet(14);
        _titleLB.textAlignment = NSTextAlignmentLeft;
        _titleLB.text = @"其他信息";
    }
    return _titleLB;
}

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleLB.bottom + 8, ScreenWidth, 190)];
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 12;
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}

- (UIButton *)pasteBtn{
    if (!_pasteBtn) {
        _pasteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _pasteBtn.frame = CGRectMake(ScreenWidth - 55, 20, 40, 20);
        _pasteBtn.clipsToBounds = YES;
        _pasteBtn.layer.cornerRadius = 10;
        _pasteBtn.layer.borderWidth = 1;
        _pasteBtn.layer.borderColor = MainPureColor(220).CGColor;
        [_pasteBtn.titleLabel setFont:FontSet(11)];
        [_pasteBtn setTitle:@"复制" forState:normal];
        [_pasteBtn setTitleColor:MainPureColor(119) forState:normal];
        [_pasteBtn addTarget:self action:@selector(pasteClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pasteBtn;
}

-(void)pasteClick{
    [Configuration pasteWithString:self.model.orderno];
}


@end




